# -*- coding: utf8 -*-
__author__ = 'Sergey Dryabzhinsky'

__doc__ = """
Обработка изображения

@author: Sergey Dryabzhinsky
"""

def load_image( file_name ):
    """
    Loads image and fill some data

    @return:    data from image:
                {
                    "width" : int,
                    "height" : int,
                    "mode"  : str
                    "image" : object
                }
    @rtype:     dict
    """

    result = {
        "width" : 0,
        "height" : 0,
        "mode" : "",
        "image" : None
    }

    # from libs.python32.x86_64.PIL.Image import open as open_image
    from Image import open as open_image

    im = open_image( file_name )

    result["mode"] = im.mode
    result["width"], result["height"] = im.size

    result["image"] = im
    return result

def is_image( file_name ):
    """
    Loads image and fill some data

    @return:    is file an image
    @rtype:     bool
    """
    result = False
    try:
        load_image(file_name)
        result = True
    except:
        pass
    return result
